<div class="jxkhzq" style="height:100%;width:100%;overflow: hidden;">
    <div class="button-group-head" style="">
        <span class="hrp-btn hrp-btn-add"  id="openDialog"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        <span  class="hrp-btn hrp-btn-refresh"><i class="fa fa-refresh" style="padding-right: 4px;"></i>刷新</span>
    </div>
    <div >
        <table id="dg" class="easyui-datagrid" style="width:100%;">
            <!--<thead>-->
            <!--<tr>-->
            <!--<th  width="15%">Item ID(15%)</th>-->
            <!--<th  width="15%">Product(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th width="15%">List Price(15%)</th>-->
            <!--</tr>-->
            <!--</thead>-->
        </table>
    </div>



    <div id="editActionDialog"  class="ss-dialog" style="height: 300px;">
        <span class="ss-dialog-close" style="">X</span>
        <div class="ss-dialog-head" style="">
            添加
        </div>
        <div class="ss-dialog-content">
            <div class="row" style="height: 60px;">
                <input type="hidden" id="idkey" value="-1"/>
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">开始日期</span>
                <span style="width:33%;float:left;padding-top: 10px;"><input id="ksrq" type="text" value="0" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:6%;height:60px;line-height:60px;float:left;text-align: center;"></span>
                <span style="width:33%;float:left;padding-top: 10px;"><input type="text"  id="ksrq-min" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" placeholder="输入指标名称" /></span>
            </div>
            <div class="row" style="height: 60px;">
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">结束日期</span>
                <span style="width:33%;float:left;padding-top: 10px;"><input id="jsrq" type="text" value="0" style="margin: 0;padding: 0;height:35px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:6%;height:60px;line-height:60px;float:left;text-align: center;"></span>
                <span style="width:33%;float:left;padding-top: 10px;"><input id="jsrq-min" type="text" value="0" style="margin: 0;padding: 0;height:35px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
            </div>
            <div class="row" style="height: 60px;">
                <span style="width:17%;height:60px;line-height:60px;float:left;text-align: center;">账期名称</span>
                <span style="width:33%;float:left;"><input id="zqmc" disabled="disabled"  type="text" value="0" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
            </div>
        </div>
        <div  class="ss-dialog-head" style="">
            <span class="hrp-btn hrp-btn-delete"  style="float: right;" id="btn-cancel"><i class="fa fa-close" style="padding-right: 4px;"></i>取消</span>
            <span class="hrp-btn hrp-btn-add" style="float: right;" id="btn-save"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        </div>
    </div>
    <div id="mask-model" class="mask-model" style=""></div>



</div>
<script type="text/javascript">
    var dHeight = $(".jxkhzq").height()-42;
    var UserIndexPage={
        init:function () {
            this.initEvnets();
            this.initPlugins();
            this.initGrid();
        },
        initEvnets:function () {
            var that = this;

            $("#openDialog").on("click",function () {
                $("#idkey").val("-1");
                $("#mask-model").slideDown(300,function () {
                    $('#editActionDialog').slideDown(300);
                });
            })

            $(".ss-dialog-close").on("click",function () {
                $('#editActionDialog').slideUp(300,function () {
                    $("#mask-model").slideUp(300);
                });
            })

            $("#btn-cancel").on("click",function () {
                $('#editActionDialog').slideUp(300,function () {
                    $("#mask-model").slideUp(300);
                });
            })

            $("#btn-save").on("click",function () {
                that.saveKhzqData();
            })

            $(".jxkhzq").on("click",".btn-excutezq",function () {
                var id= $(this).attr("data-id");
                that.excutingzq(id);
            })
        },
        excutingzq:function (zqid) {
            $.post("/jxkhzq/excutingzq",{"zqid":zqid},function (result) {
                if(result.status==200){
                    $.messager.show({title: '提示', msg: '账期执行成功', timeout: 1000, showType: 'slide'});
                }else{
                    $.messager.show({title: '提示', msg: '账期执行失败', timeout: 1000, showType: 'slide'});
                }
            })
        },
        saveKhzqData:function () {
            var ksrq=$('#ksrq').datebox('getValue');
            var ksrqMin = $('#ksrq-min').timespinner('getValue');
            var jsrq = $('#jsrq').datebox('getValue');
            var jsrqMin = $('#jsrq-min').timespinner('getValue');

            if(jsrq<=ksrq){
                $.messager.show({title: '提示', msg: '结束日期确认大于开始日期', timeout: 1000, showType: 'slide'});
            }


            var ksrqArr = ksrq.split("-");
            ksrq = ksrqArr[0]+ksrqArr[1]+ksrqArr[2]+" " + ksrqMin;
            var jsrqArr = jsrq.split("-");
            jsrq =jsrqArr[0]+jsrqArr[1]+jsrqArr[2]+" "+jsrqMin;

            var year =ksrqArr[0]+"";
            var month = ksrqArr[1]+"";
            var day = ksrqArr[2]+"";
            var zqdm = ksrqArr[0]+ksrqArr[1]+"";
            var zqmc = zqdm+"账期"


            $.post("/jxkhzq/saveKhzqData",{"zqdm":zqdm,"zqmc":zqmc,"kssj":ksrq,"jssj":jsrq,"zqyear":year,"zqmonth":month,"zqday":day},function (result) {
                if(result.status==200){
                    $('#editActionDialog').slideUp(300,function () {
                        $("#mask-model").slideUp(300);
                    });
                    $.messager.show({title: '提示', msg: '账期生成成功', timeout: 1000, showType: 'slide'});
                }else{
                    $.messager.show({title: '提示', msg: '账期生成失败', timeout: 1000, showType: 'slide'});
                }
            })


        },
        initPlugins:function () {
            var that = this;

            $('#ksrq').datebox({
                formatter : function(date){
                    var year = date.getFullYear();
                    var month = date.getMonth() + 1;
                    var day = date.getDate();
                    var hour = date.getHours();
                    month = month < 10 ? '0' + month : month;
                    day = day < 10 ? '0' + day : day;
                    hour = hour < 10 ? '0' + hour : hour;
                    return year + "-" + month + "-" + day ;
                },
                parser:function (s) {
                    s = s.replace(/\s+/,' ');//解决格式字符串中多个空格拼接在Firefox中无法兼容的问题
                    var t = Date.parse(s);
                    if (!isNaN(t)){
                        return new Date(t);
                    } else {
                        return new Date(s + ":00");
                    }
                },
                onSelect:function (date) {
                    //alert(date.getFullYear()+":"+(date.getMonth()+1)+":"+date.getDate());
                    var year = date.getFullYear();
                    var month = date.getMonth() + 1;
                    month = month < 10 ? '0' + month : month;
                    var zqmc = year + "" + month + "账期";
                    $("#zqmc").val(zqmc);
                }
            });
            $('#ksrq').datebox('setValue', that.formatterDate(new Date()));


            $('#ksrq-min').timespinner({
                min: '00:00:00',
                required: true,
                showSeconds: true
            });
            $('#ksrq-min').timespinner('setValue', '00:00:00');


            $('#jsrq').datebox({
                formatter : function(date){
                    var year = date.getFullYear();
                    var month = date.getMonth() + 1;
                    var day = date.getDate();
                    var hour = date.getHours();
                    month = month < 10 ? '0' + month : month;
                    day = day < 10 ? '0' + day : day;
                    hour = hour < 10 ? '0' + hour : hour;
                    return year + "-" + month + "-" + day ;
                },
                parser:function (s) {
                    s = s.replace(/\s+/,' ');//解决格式字符串中多个空格拼接在Firefox中无法兼容的问题
                    var t = Date.parse(s);
                    if (!isNaN(t)){
                        return new Date(t);
                    } else {
                        return new Date(s + ":00");
                    }
                }
            });
            $('#jsrq').datebox('setValue', that.formatterDate(new Date()));


            $('#jsrq-min').timespinner({
                min: '00:00:00',
                required: true,
                showSeconds: true
            });
            $('#jsrq-min').timespinner('setValue', '23:59:59');
        },
        //得到当前日期
        formatterDate : function(date,type) {
            var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
            var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1);
            return date.getFullYear() + '-' + month + '-' + day;

        },
        initGrid:function () {
            $('#dg').datagrid({
                url: "jxkhzq/getJxkhzqByPage",
                pagination: true,
                singleSelect: true,
                height:dHeight,   //表格高度，可指定高度，可自动
                pageNumber: 1,
                pageSize: 15,
                pageList: [15, 30],
                loadMsg: "正在加载数据",
                nowrap: false,
                striped: true,  //奇偶行是否使用不同的颜色
                  columns:[
                      [
                       {field:'id',title:'编号',width:"10%"},
                       {field:'zqdm',title:'账期代码',width:"10%"},
                       {field:'zqmc',title:'账期名称',width:"20%"},
                       {field:'kssj',title:'开始时间',width:"20%"},
                       {field:'jssj',title:'结束时间',width:"20%"},
                          {field:'zxzt',title:'执行状态',width:"20%",
                              formatter: function(value,row,index){
                                if(value=="0"){
                                    return "<a href='#' data-id='"+row.id+"' class='btn-excutezq'>未执行</a>"
                                }else{
                                    return "<a href='#'>已经执行</a>"
                                }
                              }
                          }
                     ]
                  ]

            });

        }
    }
    $(function () {
        UserIndexPage.init();
    })
</script>